package xyz.lwm.lazycat.web.route;

import lombok.AllArgsConstructor;
import xyz.lwm.lazycat.web.handle.Handler;
import xyz.lwm.lazycat.web.handle.HandlerType;

/**
 * router
 *
 * @author lwm
 */
@AllArgsConstructor
public class RouterImpl implements Router {

    private final RouteTable routeTable;

    @Override
    public void add(Route route) {
        routeTable.add(route);
    }

    @Override
    public void proxy(String path, Handler handler) {
        routeTable.add(path, HandlerType.PROXY, handler);
    }

    @Override
    public void before(Handler handler) {
        routeTable.add("*", HandlerType.BEFORE, handler);
    }

    @Override
    public void before(String pattern, Handler handler) {
        routeTable.add(pattern, HandlerType.BEFORE, handler);
    }

    @Override
    public void after(Handler handler) {
        routeTable.add("*", HandlerType.AFTER, handler);
    }

    @Override
    public void after(String pattern, Handler handler) {
        routeTable.add(pattern, HandlerType.AFTER, handler);
    }

    @Override
    public void get(String path, Handler handler) {
        routeTable.add(path, HandlerType.GET, handler);
    }

    @Override
    public void post(String path, Handler handler) {
        routeTable.add(path, HandlerType.POST, handler);
    }

    @Override
    public void put(String path, Handler handler) {
        routeTable.add(path, HandlerType.PUT, handler);
    }

    @Override
    public void delete(String path, Handler handler) {
        routeTable.add(path, HandlerType.DELETE, handler);
    }

    @Override
    public void patch(String path, Handler handler) {
        routeTable.add(path, HandlerType.PATCH, handler);
    }

    @Override
    public void head(String path, Handler handler) {
        routeTable.add(path, HandlerType.HEAD, handler);
    }

}
